home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Communications / Network / MacHTTP 1.2.4 / sample.script < prev    next >
Text File  |  1994-02-23  |  2KB  |  54 lines

  1. -- This script demonstrates using AppleScript with MacHTTP to generate
  2. -- dynamic World Wide Web documents.
  3. --
  4. -- MacHTTP will only read and execute scripts that have been saved as
  5. -- text only. Once the script is loaded by MacHTTP, it is passed to the default
  6. -- scripting system (usually AppleScript) for your server for execution.
  7. -- MacHTTP prepends the script's source code with a line that is the equivalent of:
  8. -- set http_request to "<request from client>"
  9. -- where <request from client> is the actual data received from the WWW client.
  10. --
  11. -- The result of the script execution is then returned to the client as a HTML
  12. -- document. The following script shows how to turn AppleScript results into HTML.
  13.  
  14. set crlf to (ASCII character 13) & (ASCII character 10)
  15. set http_10_header to "HTTP/1.0 200 OK" & crlf & "Server: MacHTTP" & crlf & ¬
  16.     "MIME-Version: 1.0" & crlf & "Content-type: text/html" & crlf & crlf
  17.  
  18. set file_path to ":" -- if this script is in a subdirectory below MacHTTP, change this to the proper relative path
  19.  
  20. -- Create the title for the HTML document
  21.  
  22. set header to http_10_header & "<title>Script Test One</title><h1>This is a test:</h1>"
  23.  
  24. -- Add some text to the body of the document
  25.  
  26. set body to "This is a test of special chars. See \"Spot\" run! Here's a backslash -> \\"
  27.  
  28. -- Show the current time on the server
  29.  
  30. set body to body & "<h2>The time is:</h2>" & (current date)
  31.  
  32. -- The following shows how to reference the args passed in from MacHTTP
  33.  
  34. set args to "<h2>Arguments passed in:</h2>" & http_request
  35. set search_args to "<h2>Search arguments:</h2>" & http_search_args
  36.  
  37. -- Show all the files in the folder "file_path" and turn HTML files into anchors
  38.  
  39. set filelist to "<h2>Files on the server:</h2><ul>"
  40. set listing to (list folder file file_path)
  41. repeat with i from 1 to the number of items in listing
  42.     set one_file to item i of listing
  43.     if one_file contains ".html" or one_file contains ".script" then
  44.         set filelist to filelist & "<li><a href=\"" & one_file & "\">" & one_file & "</a>"
  45.     else
  46.         set filelist to filelist & "<li>" & one_file
  47.     end if
  48. end repeat
  49. set filelist to filelist & "</ul>"
  50.  
  51. -- send it all back to the server for transmission to the client
  52.  
  53. return header & body & args & search_args & filelist
  54.